package com.example.springboot_demo.controller;

import com.example.springboot_demo.dto.Goods;
import com.example.springboot_demo.dto.request.GoodsRequest;
import com.example.springboot_demo.service.GoodsService;
import com.example.springboot_demo.utils.AjaxResult;
import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <P> @Author: SongKeCheng
 * <P> Type: Class
 * <P> Description:
 * <P> Date: 2024/6/23:16:47
 */

@SuppressWarnings({"unchecked", ""})
@RestController
@RequestMapping("/goods")
public class GoodsController {
    private static final Logger log = LoggerFactory.getLogger(GoodsController.class);

    @Autowired
    private GoodsService goodsService;


    /**
     * 根据id 查询商品信息
    */
    @GetMapping
    public AjaxResult findById(Integer id){
      Goods goods =  goodsService.findById(id);
      return AjaxResult.success(goods);
    }


    @PostMapping
    public AjaxResult addGoods(@RequestBody GoodsRequest goodsRequest ){
       return goodsService.addGoods(goodsRequest);
    }


    @SneakyThrows
    @PostMapping("/testTran")
    public AjaxResult testTran(@RequestBody GoodsRequest goodsRequest ){
        return goodsService.testTransactional1(goodsRequest);
    }

    @PostMapping("/findByPage")
    public AjaxResult findByPage(@RequestBody GoodsRequest goodsRequest ){
        return goodsService.findByPage(goodsRequest);
    }


}
